import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_page/mine_business/ai/ai_change_face_logic.dart';
import 'package:tiktokadult/hj_page/mine_business/ai/ai_face_sub_page.dart';
import 'package:tiktokadult/tools_base/indicator/custom_tab_indicator.dart';
import 'package:tiktokadult/tools_base/loading/l_error_widget.dart';
import 'package:tiktokadult/tools_base/loading/loading_center_widget.dart';
import 'package:tiktokadult/tools_base/widget/keep_alive_widget.dart';

//ai换脸
class AIChangeFacePage extends StatefulWidget {
  final int type; //0-图片换脸 1-视频换脸
  const AIChangeFacePage({super.key, this.type = 0});

  @override
  State<AIChangeFacePage> createState() => _AIChangeFacePageState();
}

class _AIChangeFacePageState extends State<AIChangeFacePage> {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<AIChangeFaceLogic>(
      init: AIChangeFaceLogic(type: widget.type),
      global: false,
      builder: (_) {
        if (_.dataList == null) return LoadingCenterWidget();
        if (_.dataList?.isEmpty == true) return CErrorWidget();
        return Column(
          children: [
            _buildTabbar(_),
            Expanded(
              child: TabBarView(
                controller: _.tabCtr,
                children: List.generate(
                  _.dataList?.length ?? 0,
                  (index) => AIFaceChangeSubPage(
                    type: widget.type, //0-图片换脸 1-视频换脸
                    mod: _.dataList?[index],
                  ).keepAlive,
                ),
              ),
            )
          ],
        );
      },
    );
  }

  _buildTabbar(AIChangeFaceLogic logic) {
    return TabBar(
      padding: EdgeInsets.symmetric(horizontal: 16),
      tabAlignment: TabAlignment.start,
      controller: logic.tabCtr,
      isScrollable: true,
      tabs: List.generate(
        logic.dataList?.length ?? 0,
        (index) => Padding(
          padding: const EdgeInsets.only(top: 12, bottom: 4),
          child: Text(logic.dataList?[index].name ?? ''),
        ),
      ),
      labelColor: Colors.white.withOpacity(.9),
      labelPadding: EdgeInsets.symmetric(horizontal: 12),
      labelStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
      unselectedLabelColor: Colors.white.withOpacity(0.45),
      unselectedLabelStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400),
      indicator: CustomIndicator(
        width: 13,
        height: 3,
        topLeft: 12,
        topRight: 12,
        bottomLeft: 12,
        bottomRight: 12,
        useGradient: true,
        gradientColors: [
          Color(0xffE1351F).withOpacity(0),
          Color(0xffE1351F),
        ],
      ),
    );
  }
}
